import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-04-19
 * Time: 23:17
 */
public class test_2 {
    static int num;
    static int maxcnt = 0;
    static int mid = 0;
    static int left = 0;
    static int right = 0;

    static void split(int[] a, int low, int high) {
        mid = (low + high) / 2;
        for (left = low; left <= high; left++) {
            if (a[left] == a[mid]) {
                break;
            }
        }
        for (right = left + 1; right <= high; right++) {
            if (a[right] != a[mid]) {
                break;
            }
        }
        right--;
    }

    static void getmaxcnt(int[] a, int low, int high) {
        if (low <= high) {
            split(a, low, high);
            int cnt = right - left + 1;
            if (cnt > maxcnt) {
                num = a[mid];
                maxcnt = cnt;
            }
            getmaxcnt(a, low, left - 1);
            getmaxcnt(a, right + 1, high);
        }
    }

    public static void main(String[] args) {
        int[] a = {1, 2, 2, 2, 3, 3, 5, 6, 6, 6, 6};
        int n = a.length;
        System.out.println("求解过程");
        System.out.println("递增序列");
        System.out.println(Arrays.toString(a));
        getmaxcnt(a, 0, n - 1);
        System.out.printf("众数：%d,重数：%d\n", num, maxcnt);
    }
}
